﻿using DevExpress.Mvvm;
using orm.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OneStress.PropertyNodes
{
    internal class SiteNode : PropertyNode<TgsTDSite>
    {
        public SiteNode(Guid id)
        {
            var dbContext = ServiceContainer.Default.GetService<IDisposable>("DBSerice") as OneSysDBContext;

            _current = dbContext.TgsTDSite.Where(v => v.SiteId == id.ToString()).FirstOrDefault();
        }

        [Category("General")]
        public override string Name
        {
            get
            {
                return _current?.SiteName;
            }
            set
            {
                _current.SiteName = value;
            }
        }

        [Category("General")]
        public string District
        {
            get
            {
                return _current?.DistrictName;
            }
            set
            {
                _current.DistrictName = value;
            }
        }

        [Category("General")]
        public string Block
        {
            get
            {
                return _current?.BlockName;
            }
            set
            {
                _current.BlockName = value;
            }
        }


        [Category("Location")]
        public string Lease
        {
            get
            {
                return _current?.LocLeaseCode;
            }
            set
            {
                _current.LocLeaseCode = value;
            }
        }

        [Category("Location")]
        public string Country
        {
            get
            {
                return _current?.LocCountry;
            }
            set
            {
                _current.LocCountry = value;
            }
        }

        [Category("Location")]
        public string County
        {
            get
            {
                return _current?.LocCounty;
            }
            set
            {
                _current.LocCounty = value;
            }
        }


        [Category("CentreLocation")]
        public double ScaleFactor
        {
            get
            {
                return _current?.ScaleFactor??1.0;
            }
            set
            {
                _current.ScaleFactor = value;
            }
        }

        [Category("CentreLocation")]
        public double Northing
        {
            get
            {
                return _current?.YCoord ?? 0.0;
            }
            set
            {
                _current.YCoord = value;
            }
        }

        [Category("CentreLocation")]
        public double Easting
        {
            get
            {
                return _current?.XCoord ?? 0.0;
            }
            set
            {
                _current.XCoord = value;
            }
        }

        [Category("AziRef")]
        public NorthType NorthType
        {
            get
            {
                return (NorthType)(_current?.NorthType ?? 0) ;
            }
            set
            {
                _current.NorthType = (long)value;
            }
        }

        [Category("AziRef")]
        public double Convergence
        {
            get
            {
                return _current?.Convergence ?? 0;
            }
            set
            {
                _current.Convergence = value;
            }
        }

    }
}
